﻿
Public Class operationJob
    Inherits basicJob(Of operationJob, String)

    Private Shared ReadOnly field_types() As Type = Nothing

    Shared Sub New()
        field_types = New Type() {GetType(bytesByte),
                                  GetType(bytesString),
                                  GetType(bytesString),
                                  GetType(bytesBoolean),
                                  GetType(bytesInt32)}
    End Sub

    Public command As Byte = job.command.invalid
    Private _id As String = Nothing
    Public action As String = Nothing
    Public result As Boolean = False
    Public percentage As Int32 = 0

    Public Function id() As String
        Return _id
    End Function

    Protected Overrides Sub auto_fill()
        MyBase.auto_fill()
        _id = createGUID()
    End Sub

    Protected Overrides Function alloc() As operationJob
        Return New operationJob()
    End Function

    Protected Overrides Sub copy(ByVal i As operationJob)
        assert(Not i Is Nothing)
        copy(command, i.command)
        copy(_id, i.id())
        copy(action, i.action)
        copy(result, i.result)
        copy(percentage, i.percentage)
    End Sub

    Protected Overrides Sub frombytes()
        command = next_para().as(Of Byte)()
        _id = next_para().as(Of String)()
        action = next_para().as(Of String)()
        result = next_para().as(Of Boolean)()
        percentage = next_para().as(Of Int32)()
    End Sub

    Protected Overrides Function hashcode_key() As String
        Return id()
    End Function

    Protected Overrides Function paras() As toBytes()
        Return New toBytes() {New bytesByte(command),
                              New bytesString(id()),
                              New bytesString(action),
                              New bytesBoolean(result),
                              New bytesInt32(percentage)}
    End Function

    Protected Overrides Function types() As Type()
        Return field_types
    End Function
End Class
